<?php
/**
 * 处理用户注册
 * 业务逻辑：
 * 1.获取登录表单上的用户注册信息
 * 2.调用数据层的相应方法：add_user()
 * 3.注册成功跳转到login.php,失败跳转到error.php
 */
require "../model/userDao.php";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
  // 获取登录表单上的用户信息
  $uname = $_POST["uName"];
  $upass = $_POST["uPass"];
  $gender = $_POST["gender"];
  $head = $_POST["head"];
  $is = "reg";
  // 调用get_user()，判断是否重复用户名
  $result = get_user( $uname, $upass);
  if (count($result) == 0) {
    // 调用add_user()
    $result2 = add_user($uname, $upass, $head, $gender);
    if ($result2 > 0) {
      // 跳转到index.php
      header("location:../views/login.php?reg=1");
    } else {
      header("location:../views/error.php?msg=注册失败");
    }
  } else {
    header("location:../views/error.php?msg=用户名重复，请重新输入");
  }
} else {
  header("location:../views/error.php?msg=非法访问");
}
?>